/**
 * Created by wurenjie on 15/5/21.
 */
$(function(){
    $.feelywiki.init({
        "titleElem" : "#wiki-title",
        "wikiPrefix" : "/wiki/",
        "redirectParam" : "redirectfrom"
    });
    $("#wiki-content").html($.feelywiki.start($("#wikiEdit-textarea").val()));
    $("#wikiWrite-save").click(function(){
        ChangePage();
    })
});
function ChangePage(){
    var content=$("#wikiEdit-textarea").val();
    var title=$("#wikiEdit-title").val();
    var reason=$("#wikiWrite-reason").val();
    var wikiid=$("#wikiPage-id").val();
    $.post("/wikido/edit.json",{
        title:title,
        content:content,
        reason:reason,
        wikiid:wikiid
    },function(data){
        data=JSON.parse(data);
        if(data.result=="error"){
            popover_open_info(data.info)
        }
        else{
            popover_open_info("保存成功<br>两秒后自动跳转");
            setTimeout(function(){
                location.href="/wiki/"+title;
            },2000);
        }
    });
}